package com.gitee.dbswitch.admin.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gitee.dbswitch.admin.entity.APIAssignmentConfigEntity;
import com.gitee.dbswitch.admin.entity.AssignmentConfigEntity;
import com.gitee.dbswitch.admin.mapper.APIAssignmentConfigMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * api 配置
 *
 * @author natural
 */
@Repository
public class APIAssignmentConfigDAO {

    @Resource
    private APIAssignmentConfigMapper apiAssignmentConfigMapper;

    public void insert(APIAssignmentConfigEntity apiAssignmentConfigEntity) {
        apiAssignmentConfigMapper.insert(apiAssignmentConfigEntity);
    }

    public APIAssignmentConfigEntity getById(Long id) {
        return apiAssignmentConfigMapper.selectById(id);
    }

    public APIAssignmentConfigEntity getByAssignmentTaskId(Long taskId) {
        QueryWrapper<APIAssignmentConfigEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(APIAssignmentConfigEntity::getAssignmentId, taskId);
        return apiAssignmentConfigMapper.selectOne(queryWrapper);
    }

    public void updateSelective(APIAssignmentConfigEntity apiAssignmentConfigEntity) {
        apiAssignmentConfigMapper.updateById(apiAssignmentConfigEntity);
    }

    public void deleteByAssignmentTaskId(Long taskId) {
        QueryWrapper<APIAssignmentConfigEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(APIAssignmentConfigEntity::getAssignmentId, taskId);
        apiAssignmentConfigMapper.delete(queryWrapper);
    }

}
